/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package persistence;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * This class is a JPA entity and is used to represent a comment
 * as it will be stored in the database
 * 
 * @author Amigos do Noddy
 *
 */
@Entity
@Table(name = "COMMENT", schema = "APP")
@NamedQueries({@NamedQuery(name = "Comment.findByIdcomment", query = "SELECT c FROM Comment c WHERE c.idcomment = :idcomment"), @NamedQuery(name = "Comment.findByDate", query = "SELECT c FROM Comment c WHERE c.date = :date")})
public class Comment implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "IDCOMMENT", nullable = false)
    private Integer idcomment;
    @Lob
    @Column(name = "COMMENT", nullable = false)
    private String comment;
    @Column(name = "DATE", nullable = false)
    @Temporal(TemporalType.DATE)
    private Date date;
    @JoinColumn(name = "REFIDPERSON_AUTHOR", referencedColumnName = "IDPERSON")
    @ManyToOne
    private Person refidpersonAuthor;
    @JoinColumn(name = "REFIDTICKET", referencedColumnName = "IDTICKET")
    @ManyToOne
    private Ticket refidticket;

    /**
     * Default constructor
     */
    public Comment() {
    }

    /**
     * Class constructor
     * @param idcomment comment id
     */
    public Comment(Integer idcomment) {
        this.idcomment = idcomment;
    }

    /**
     * Class constructor
     * @param idcomment comment id
     * @param comment comment text
     * @param date comment date
     */
    public Comment(Integer idcomment, String comment, Date date) {
        this.idcomment = idcomment;
        this.comment = comment;
        this.date = date;
    }

    /**
     * Gets the id of the comment
     * @return comment id
     */
    public Integer getIdcomment() {
        return idcomment;
    }

    /**
     * Sets the id of the comment
     * @param idcomment comment id
     */
    public void setIdcomment(Integer idcomment) {
        this.idcomment = idcomment;
    }

    /**
     * Gets the comment text
     * @return comment text
     */
    public String getComment() {
        return comment;
    }

    /**
     * Sets the comment text
     * @param comment comment text
     */
    public void setComment(String comment) {
        this.comment = comment;
    }

    /**
     * Gets the date of the comment
     * @return comment date
     */
    public Date getDate() {
        return date;
    }
    
    /**
     * Sets the date of the comment
     * @param date comment date
     */
    public void setDate(Date date) {
        this.date = date;
    }

    /**
     * Gets the id of the author of the comment
     * @return id of the author
     */
    public Person getRefidpersonAuthor() {
        return refidpersonAuthor;
    }

    /**
     * Sets the id of the author of the comment
     * @param refidpersonAuthor id of the author
     */
    public void setRefidpersonAuthor(Person refidpersonAuthor) {
        this.refidpersonAuthor = refidpersonAuthor;
    }

    /**
     * Gets the id of the ticket
     * @return ticket id
     */
    public Ticket getRefidticket() {
        return refidticket;
    }

    /**
     * Sets the id of the ticket
     * @param refidticket ticket id
     */
    public void setRefidticket(Ticket refidticket) {
        this.refidticket = refidticket;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idcomment != null ? idcomment.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Comment)) {
            return false;
        }
        Comment other = (Comment) object;
        if ((this.idcomment == null && other.idcomment != null) || (this.idcomment != null && !this.idcomment.equals(other.idcomment))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "persistence.Comment[idcomment=" + idcomment + "]";
    }

}
